package com.ramos.kuaixiao.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class ShopTypeBean implements Serializable {

    private int status;
    private String msg;
    private List<ShopType> brandList = new ArrayList<>();

    public void addProductInfo(ShopType.ProductInfo info, HashMap<String, ArrayList<String>> typeMap){
        ShopType tt = null;
        if(null == (tt =isContainBrand(info.getBrandName()))){
            ShopType brand = new ShopType();
            brand.brandName = info.getBrandName();
            brand.brandId = info.getBrandId();
            brand.addProductInfo(info, typeMap);
            brandList.add(brand);
        }else{
            tt.addProductInfo(info, typeMap);
        }
    }


    private ShopType isContainBrand(String brandName){
        for(ShopType br: brandList){
            if(br.brandName.equals(brandName)){
                return br;
            }
        }
        return null;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public List<ShopType> getBrandList() {
        return brandList;
    }

    public void setBrandList(List<ShopType> brandList) {
        this.brandList = brandList;
    }

    public static class ShopType {

        private String brandName;
        private String brandId;
        private List<Type> typeGroupList= new ArrayList<>();

        public Type isContainType(String typeId){
            for(Type type: typeGroupList){
                if(type.typeId.equals(typeId)){
                    return type;
                }
            }
            return null;
        }


        public void addProductInfo(ShopTypeBean.ShopType.ProductInfo info, HashMap<String, ArrayList<String>> typeMap){
            Type gg = null;
            if(null == (gg = isContainType(info.getProductFirstTypeId()))){
                Type typeGroup = new Type();
                typeGroup.typeId = info.getProductFirstTypeId();
                typeGroup.typeName = info.getProductTypeName();
                typeGroup.addSpecificInfo(info, typeMap);
                typeGroupList.add(typeGroup);
            }else{
                gg.addSpecificInfo(info, typeMap);
            }
        }

        public String getBrandName() {
            return brandName;
        }

        public void setBrandName(String brandName) {
            this.brandName = brandName;
        }

        public String getBrandId() {
            return brandId;
        }

        public void setBrandId(String brandId) {
            this.brandId = brandId;
        }

        public List<Type> getTypeGroupList() {
            return typeGroupList;
        }

        public void setTypeGroupList(List<Type> typeGroupList) {
            this.typeGroupList = typeGroupList;
        }

        public static class Type {
            private String typeId;
            private String typeName;
            private List<Product> typeGroupList= new ArrayList<>();


            private Product isContainsItem(String typename){
                for(Product it: typeGroupList){
                    if(it.typeName.equals(typename)){
                        return it;
                    }
                }
                return null;
            }

            public void addSpecificInfo(ProductInfo info, HashMap<String, ArrayList<String>> typeMap){
                String productInfoName = info.getProductInfoName();
                String typeId = info.getProductFirstTypeId();
                ArrayList<String>keyset = typeMap.get(typeId);
                Product ii = null;
                for(String key: keyset){
                    if(info.getProductInfoName().contains(key)){
                        if((ii = isContainsItem(key))==null){
                            ii = new Product();
                            ii.typeName = key;
                            ii.typeId = typeId;
                            ii.getProductInfoNameList().add(new ProductInfo(info.getProductInfoId(),productInfoName,info.getProductBarCode()));
                            this.typeGroupList.add(ii);
                            return;
                        }else{
                            ii.getProductInfoNameList().add(new ProductInfo(info.getProductInfoId(),productInfoName,info.getProductBarCode()));
                            return ;
                        }
                    }
                }
                if((ii = isContainsItem("其他"))==null){
                    ii = new Product();
                    ii.typeName = "其他";
                    ii.typeId = typeId;
                    ii.getProductInfoNameList().add(new ProductInfo(info.getProductInfoId(),productInfoName, info.getProductBarCode()));
                    this.typeGroupList.add(ii);
                }else{
                    ii.getProductInfoNameList().add(new ProductInfo(info.getProductInfoId(),productInfoName,info.getProductBarCode()));
                }
            }

            public String getTypeId() {
                return typeId;
            }

            public void setTypeId(String typeId) {
                this.typeId = typeId;
            }

            public String getTypeName() {
                return typeName;
            }

            public void setTypeName(String typeName) {
                this.typeName = typeName;
            }

            public List<Product> getTypeGroupList() {
                return typeGroupList;
            }

            public void setTypeGroupList(List<Product> typeGroupList) {
                this.typeGroupList = typeGroupList;
            }
        }

        public static class Product {
            private String typeId;
            private String typeName;
            private List<ProductInfo> productInfoNameList= new ArrayList<>();

            public String getTypeId() {
                return typeId;
            }

            public void setTypeId(String typeId) {
                this.typeId = typeId;
            }

            public String getTypeName() {
                return typeName;
            }

            public void setTypeName(String typeName) {
                this.typeName = typeName;
            }

            public List<ProductInfo> getProductInfoNameList() {
                return productInfoNameList;
            }

            public void setProductInfoNameList(List<ProductInfo> productInfoNameList) {
                this.productInfoNameList = productInfoNameList;
            }
        }

        public static class ProductInfo implements Serializable {
            private String productInfoId;
            private String productInfoName;
            private String productBarCode;
            private String productFirstTypeId;
            private String productTypeName;
            private String productSecendTypeId;
            private String productSecendTypeName;
            public int outerUnitCount;
            private String brandName;
            private String brandId;
            private String iconUrl;
            private String status;
            public String nonTaxSalePrice;
            public int total;
            public float taxrate;
            public Long modifyTime;
            private int type;
            public String idx;
            public List<WareInfo> wareList= new ArrayList<>();

            public ProductInfo() {

            }

            public void recoverproductInfoId(){
                if(productInfoId!=null &&!productInfoId.equals("")){
                    if(productInfoId.contains("_")){
                        productInfoId = productInfoId.substring(productInfoId.indexOf("_")+1);
                    }
                }
            }

            public ProductInfo(String productInfoId, String productInfoName, String productBarCode) {
                this.productInfoId = productInfoId;
                this.productInfoName = productInfoName;
                this.productBarCode = productBarCode;

            }

            public ProductInfo(String productInfoId, String productInfoName, String productBarCode, int outerUnitCount, String nonTaxSalePrice,
                               String status, float taxrate, String productFirstTypeId, String productTypeName, String brandId, String brandName, Long modifyTime) {
                this.productInfoId = productInfoId;
                this.productInfoName = productInfoName;
                this.productBarCode = productBarCode;
                this.outerUnitCount = outerUnitCount;
                this.nonTaxSalePrice = nonTaxSalePrice;
                this.status = status;
                this.taxrate = taxrate;

                this.productFirstTypeId = productFirstTypeId;
                this.productTypeName = productTypeName;
                this.brandId = brandId;
                this.brandName = brandName;
                this.modifyTime = modifyTime;
            }

            public String getIdx() {
                return idx;
            }

            public void setIdx(String idx) {
                this.idx = idx;
            }

            public int getType() {
                return type;
            }

            public void setType(int type) {
                this.type = type;
            }

            public Long getModifyTime() {
                return modifyTime;
            }

            public void setModifyTime(Long modifyTime) {
                this.modifyTime = modifyTime;
            }

            public String getStatus() {
                return status;
            }

            public void setStatus(String status) {
                this.status = status;
            }

            public float getTaxrate() {
                return taxrate;
            }

            public void setTaxrate(float taxrate) {
                this.taxrate = taxrate;
            }

            public String getProductSecendTypeId() {
                return productSecendTypeId;
            }

            public void setProductSecendTypeId(String productSecendTypeId) {
                this.productSecendTypeId = productSecendTypeId;
            }

            public String getProductSecendTypeName() {
                return productSecendTypeName;
            }

            public void setProductSecendTypeName(String productSecendTypeName) {
                this.productSecendTypeName = productSecendTypeName;
            }

            public String getProductFirstTypeId() {
                return productFirstTypeId;
            }

            public void setProductFirstTypeId(String productFirstTypeId) {
                this.productFirstTypeId = productFirstTypeId;
            }

            public String getProductTypeName() {
                return productTypeName;
            }

            public void setProductTypeName(String productTypeName) {
                this.productTypeName = productTypeName;
            }

            public int getOuterUnitCount() {
                return outerUnitCount;
            }

            public void setOuterUnitCount(int outerUnitCount) {
                this.outerUnitCount = outerUnitCount;
            }

            public String getBrandName() {
                return brandName;
            }

            public void setBrandName(String brandName) {
                this.brandName = brandName;
            }

            public String getBrandId() {
                return brandId;
            }

            public void setBrandId(String brandId) {
                this.brandId = brandId;
            }

            public String getProductInfoId() {
                return productInfoId;
            }

            public void setProductInfoId(String productInfoId) {
                this.productInfoId = productInfoId;
            }

            public String getProductInfoName() {
                return productInfoName;
            }

            public void setProductInfoName(String productInfoName) {
                this.productInfoName = productInfoName;
            }

            public String getProductBarCode() {
                return productBarCode;
            }

            public void setProductBarCode(String productBarCode) {
                this.productBarCode = productBarCode;
            }

            public String getIconUrl() {
                return iconUrl;
            }

            public void setIconUrl(String iconUrl) {
                this.iconUrl = iconUrl;
            }

            public String getNonTaxSalePrice() {
                return nonTaxSalePrice;
            }

            public void setNonTaxSalePrice(String nonTaxSalePrice) {
                this.nonTaxSalePrice = nonTaxSalePrice;
            }

            public int getTotal() {
                return total;
            }

            public void setTotal(int total) {
                this.total = total;
            }

            public List<WareInfo> getWareList() {
                return wareList;
            }

            public void setWareList(List<WareInfo> wareList) {
                this.wareList = wareList;
            }

            public static class WareInfo {
                public int total;

                public String warehouseId;

                public String warehouseName;

                public int getTotal() {
                    return total;
                }

                public void setTotal(int total) {
                    this.total = total;
                }

                public String getWarehouseId() {
                    return warehouseId;
                }

                public void setWarehouseId(String warehouseId) {
                    this.warehouseId = warehouseId;
                }

                public String getWarehouseName() {
                    return warehouseName;
                }

                public void setWarehouseName(String warehouseName) {
                    this.warehouseName = warehouseName;
                }
            }
        }
    }
}
